<div class="layui-form" lay-filter="layuiadmin-form-role" id="agent_groupform">
	<div class="form-cont">
		<div class="layui-form-item verify">
		  <label class="layui-form-label">分组名称</label>
		  <div class="layui-input-block">
			  <input type="text" lay-verify="required" v-model="detail.agent_group_name" verify='requirel2' placeholder="请输入分组名称" class="layui-input">
			  <span class="hint">分组名称必填</span>
			</div>
		</div>
	</div>
  <div class="form-btn" v-if="type!=3">
      <input type="button" value="保存" class="layui-btn" @click="submits">
  </div>
</div>

<script>
	layui.use(['form'], function(){
	  var $ = layui.$
	  ,form = layui.form;
	  var agent_groupform=new Vue({
	  		el:'#agent_groupform',
	  		data:{
	  			detail:{},
				old_detail:{},
				type:layui.admin.objDatas.type
	  		},
	  		mounted() {
				//初始化

				//this.type=1;
				if(this.type!=1) this.detail=layui.admin.objDatas.detail,this.old_detail=JSON.stringify(layui.admin.objDatas.detail);
	  			//if(this.type!=1) this.detail=layui.admin.objDatas.detail;
	  		},
	  		methods:{
	  			submits:function(){
	  				if(layui.admin.form('#agent_groupform')){

	  					if(this.type==2){   //编辑
							var data=layui.admin.filter(this.detail,JSON.parse(this.old_detail),'group_id');


							if(data){
								layui.admin.ajax('agents/group_update',data).then(function(res){
									layer.close(layui.admin.pupsc);
									layui.table.reload('list-select-table');
								});
							}else{
								layer.close(layui.admin.pupsc);
							}

	  					}else{  //添加
							layui.admin.ajax('agents/group_add',this.detail).then(function(res){
								layer.close(layui.admin.pupsc);
								layui.table.reload('list-select-table');
							})
	  					}
	  				}
	  			}
	  		}
	  	})
	});
</script>
